package com.share.rules.api.factory;

import com.share.common.core.domain.R;
import com.share.rules.api.RemoteFeeRuleService;
import com.share.rules.api.domain.FeeRule;
import com.share.rules.api.domain.FeeRuleRequestForm;
import com.share.rules.api.domain.FeeRuleResponseVo;
import org.mybatis.logging.Logger;
import org.mybatis.logging.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;


@Component
public class RemoteFeeRuleFallbackFactory implements FallbackFactory<RemoteFeeRuleService> {
    private static final Logger log = LoggerFactory.getLogger(RemoteFeeRuleFallbackFactory.class);

    @Override
    public RemoteFeeRuleService create(Throwable cause) {
        log.error(() -> "规则服务调用失败:" + cause.getMessage(), cause);
        return new RemoteFeeRuleService() {

            @Override
            public R<List<FeeRule>> getFeeRuleList(List<Long> feeRuleIdList) {
                return R.fail("获取费用规则列表失败:" + cause.getMessage());
            }

            @Override
            public R<FeeRule> getFeeRule(Long id) {
                return R.fail("获取费用规则信息失败:" + cause.getMessage());
            }

            @Override
            public R<FeeRuleResponseVo> calculateOrderFee(FeeRuleRequestForm feeRuleRequestForm) {
                return R.fail("计算订单费用失败:" + cause.getMessage());
            }
        };
    }
}